package com.czh.springboot04.MyController;

import com.czh.springboot04.entity.Coursetalk;
import com.czh.springboot04.service.CoursetalkService;
import com.czh.springboot04.util.R;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/coursetalk")
@CrossOrigin
public class CoursetalkController {
    @Autowired
    private CoursetalkService coursetalkService;

    @PostMapping("/insert")
    public R insert(@RequestBody Coursetalk coursetalk){
        int i = coursetalkService.insert(coursetalk);
        if (i != 0) {
            return R.ok("添加成功");
        }else {
            return R.error("添加失败");
        }
    }

    @DeleteMapping("/delete")
    public R delete(int id){
        int i = coursetalkService.delete(id);
        if (i!= 0) {
            return R.ok("删除成功");
        }else {
            return R.error("删除失败");
        }
    }

    @PutMapping("/update")
    public R update(@RequestBody Coursetalk coursetalk){
        int i = coursetalkService.update(coursetalk);
        if (i!= 0) {
            return R.ok("修改成功");
        }else {
            return R.error("修改失败");
        }
    }

    @GetMapping("/select")
    public R select(int pageNum,int pageSize,String nickName,String courseName){
        PageInfo<Coursetalk> pageInfo = coursetalkService.select(pageNum, pageSize, nickName, courseName);
        return R.ok(pageInfo);
    }
}
